#ifndef	XX_COMMON_SYSTEM_INCLUDE_HH
#define	XX_COMMON_SYSTEM_INCLUDE_HH

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>       // std::string
#include <iostream>     // std::cout
#include <sstream>      // std::stringstream

#include <math.h>
#include <errno.h>
#include <ctype.h>
#include "log4z.h"

typedef char 			int8;
typedef char 			int24[3];
typedef short 			int16;
typedef int 			int32;

typedef unsigned char 	uint8;
typedef unsigned short 	uint16;
typedef unsigned char 	uint24[3];
typedef unsigned int 	uint32;

#define  VERSION_SN	 "20211013"

#ifdef	WIN32

#include <ws2tcpip.h>
#include <ws2ipdef.h>

#include <MSWSock.h>
#include <winsock2.h>
#include <mmsystem.h>

#include <io.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>

#include <malloc.h>
#include <time.h>
#include <process.h>
#include <iphlpapi.h>
#include <assert.h>

#pragma comment(lib, "ws2_32.lib")
#pragma comment(lib, "winmm.lib")

#define  GB35114				0
typedef SOCKET					socket_t;
typedef __int64					int64;
typedef unsigned __int64		uint64;

#define strcasecmp 				_stricmp
#define snprintf 				_snprintf
#define strncasecmp 			_memicmp
#define close(s)				closesocket(s)
#else

#include <sys/types.h>
#include <sys/ipc.h>
#include <semaphore.h>
#include <signal.h>

#include <sys/ioctl.h>
#include <sys/socket.h>
#include <sys/epoll.h>

#include <netinet/in.h>
#include <netinet/ip.h>
#include <netinet/tcp.h>

#include <arpa/inet.h>
#include <netdb.h>

#include <net/if.h>
#include <sys/resource.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <sys/time.h>

#include <ctype.h>
#include <unistd.h>
#include <stdarg.h>
#include <fcntl.h>
#include <errno.h>
#include <time.h>
#include <assert.h>
#include <pthread.h>

#include <dlfcn.h>
#include <dirent.h>
#include <ifaddrs.h>
#include <sys/prctl.h>
#include <unistd.h>

typedef int							socket_t;
typedef long long					int64;
typedef unsigned long long			uint64;

#define  GB35114					 0		//yanghongbo
#define INFINITE					-1
#define	SOCKET_ERROR				-1
#define INVALID_SOCKET				-1
#define WSAGetLastError()          errno

#endif

#define SOCKET_NONE						0x00
#define MAX_MTU_SIZE					0x600
#define MAX_BUFFER_01					0x01
#define MAX_BUFFER_64					0x40	 //64byte
#define MAX_BUFFER_128					0x80	 //128byte
#define MAX_BUFFER_256					0x100	 //256byte
#define MAX_BUFFER_512					0x200	 //512byte
#define MAX_BUFFER_1KSZ					0x400	 //1k
#define MAX_BUFFER_4KSZ					0x1000	 //4k
#define MAX_BUFFER_8KSZ					0x2000
#define MAX_BUFFER_16KSZ				0x4000
#define MAX_BUFFER_32KSZ				0x8000
#define MAX_BUFFER_64KSZ				0x10000
#define MAX_BUFFER_128KSZ				0x20000
#define MAX_BUFFER_256KSZ				0x40000
#define MAX_BUFFER_512KSZ				0x80000
#define MAX_BUFFER_1MSIZE				0x100000
#define MAX_BUFFER_2MSIZE				0x200000
#define MAX_BUFFER_4MSIZE				0x400000

#define xx_alloc(xx,var)						\
	xx* var = (xx*)malloc(sizeof(xx));			\
	if(NULL == var){							\
		return ;								\
	}											\
	memset(var, 0, sizeof(xx));

#define xx_rtalloc(xx,var,Ret)					\
	xx* var = (xx*)malloc(sizeof(xx));			\
	if(NULL == var){							\
		return Ret;								\
	}											\
	memset(var, 0, sizeof(xx));

#define xx_malloc(xx,var,sz)					\
	xx* var = (xx*)malloc(sizeof(xx)+sz);		\
	if(NULL == var){							\
		return ;								\
	}

#define xx_rtmalloc(xx,var,sz,Ret)				\
	xx* var = (xx*)malloc(sizeof(xx)+sz);		\
	if(NULL == var){							\
		return Ret;								\
	}

#define xl_alloc(xx,var)						\
	var = (xx*)malloc(sizeof(xx));				\
	if(NULL == var){							\
		return ;								\
	}											\
	memset(var, 0, sizeof(xx));

#define xl_rtalloc(xx,var,Ret)					\
	var = (xx*)malloc(sizeof(xx));				\
	if(NULL == var){							\
		return Ret;								\
	}											\
	memset(var, 0, sizeof(xx));

#define xl_malloc(xx,var,sz)					\
	var = (xx*)malloc(sizeof(xx)+sz);			\
	if(NULL == var){							\
		return ;								\
	}

#define xl_rmalloc(xx,var,sz,Ret)				\
	var = (xx*)malloc(sizeof(xx)+sz);			\
	if(NULL == var){							\
		return Ret;								\
	}

#define XX_NEW(POINTER,CONSTRUCTOR)				\
	 CONSTRUCTOR* POINTER = new CONSTRUCTOR();	\
    if (NULL == POINTER){						\
		return ;								\
	}

#define XX_NEW_RET(POINTER,CONSTRUCTOR,RET_VAL)	\
	 CONSTRUCTOR* POINTER = new CONSTRUCTOR;	\
     if (NULL == POINTER){						\
		return RET_VAL;							\
	 }


#define XX_STATIC_DECLARE(class_name)			\
public:											\
	static class_name* xInstance();

#define XX_STATIC_IMP(class_name)				\
	class_name * class_name::xInstance(){		\
        static class_name m_instance;           \
		return &m_instance;						\
	}

#define xx_memcpy(p, off, ch, len)				memcpy(p + off, ch, len);	\
												off += len;

#define xx_min(a, b)							(a < b) ? a : b
#define xx_max(a, b)							(a > b) ? a : b
#define xx_div(a, b)							(a + b - 1) / b



#define SAFE_FREE(P)						if (P){free(P); P = NULL;}
#define SAFE_DELETE(P)                      if (P){delete P; P = NULL;}
#define SAFE_DELETEA(P)                     if (P){delete[] P; P = NULL;}
#define SAFE_DELETEHD(P)					if (P){CloseHandle(P); P = NULL;}


#define XX_ERR_TURE							 1  /* no error */
#define XX_ERR_NONE							 0  /* no error */
#define	XX_ERR_ERROR						-1  /* no error */
#define	XX_ERR_MEMORY						-2  /* null pointer */
#define	XX_ERR_INVALID						-3  /* no error */
#define	XX_ERR_NOTDATA						-4
#define	XX_ERR_TIMEOUT						-5

#if __cplusplus >= 201103L
#else
//std::string& to_string(int n)
//{
//	std::stringstream ss;
//	ss << n;
//	std::string s1 = ss.str();
//	return s1;
//}
#endif // __cplusplus >= 201103L

#endif	//	__SYS_INC_H__



